package com.hnust.dao;

import com.hnust.domain.College;
import com.hnust.domain.Major;
import com.hnust.domain.Student;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface StudentDao {

    //Test
    @Select("select maj_id,name from major where col_id=#{collegeId}")
    @ResultType(Major.class)
    List<Major> getMajor(String collegeId);

    //添加学生
    @Insert("insert into student (stu_id, account, alias, name, stu_number, pho_number, e_mail, password, school, cls_id) value (#{stu_id}, #{account}, #{alias}, #{name}, #{stu_number}, #{pho_number}, #{e_mail}, #{password}, #{school}, #{cls_id})")
    @ResultType(Integer.class)
    Integer addStudent(String stu_id, String account, String alias, String name, String stu_number, String pho_number, String e_mail, String password, String school, String cls_id);

    //ID查找学生
    @Select("select * from student where stu_id = #{id}")
    @ResultType(Student.class)
    Student queryStudentById(String id);

    //账号查找学生
    @Select("select * from student where account = #{account}")
    @ResultType(Student.class)
    Student queryStudentByAccount(String account);

    //邮箱查找学生
    @Select("select * from student where e_mail = #{mail} ")
    @ResultType(Student.class)
    Student queryStudentByEmail(String mail);

    //修改学生信息
    @Update("update student set alias=#{alias}, name=#{name}, stu_number=#{stu_number}, pho_number=#{pho_number}, e_mail=#{e_mail}, password=#{password}, school=#{school}, cls_id=#{cls_id} where stu_id=#{id}")
    @ResultType(Integer.class)
    Integer modifyStudentById(String id, String alias, String name, String stu_number, String pho_number, String e_mail, String password, String school, String cls_id);

    //修改学生无班级信息
    @Update("update student set alias=#{alias}, name=#{name}, stu_number=#{stu_number}, pho_number=#{pho_number}, e_mail=#{e_mail}, password=#{password}, school=#{school} ,cls_id=NULL where stu_id=#{id}")
    @ResultType(Integer.class)
    Integer modifyStudentClassNoneById(String id, String alias, String name, String stu_number, String pho_number, String e_mail, String password, String school,String cls_id);
    //获取学生信息
    @Select("select * from student where stu_id=#{studentId}")
    @ResultType(Student.class)
    Student getStudent(String studentId);

    //查询学院
    @Select("select * from college")
    @ResultType(College.class)
    List<College> getCollege();

    //根据班级号查询学生
    @Select("select * from student where cls_id=#{cls_id} ")
    @ResultType(Student.class)
    List<Student> queryStudentsByClassId(String classId);

    //获取所有学生
    @Select("select * from student")
    @ResultType(Student.class)
    List<Student> queryAllStudent();


}
